﻿#define _CRT_SECURE_NO_WARNINGS 1

#include "mineSweeping.h"

int mode = 1;

void easyMode()
{
	char mine[EASY_ROWS][EASY_COLS] = { 0 };//初始化为全'0'
	char show[EASY_ROWS][EASY_COLS] = { 0 };//初始化为全'*'

	//初始化棋盘
	InitBoard(mine, EASY_ROWS, EASY_COLS, '0');
	InitBoard(show, EASY_ROWS, EASY_COLS, '*');

	//布置雷
	setMine(mine, EASY_ROW, EASY_COL);

	//DisplayBoard(mine, EASY_ROW, EASY_COL);//打印棋盘

	//排查雷
	CheckMine(mine, show, EASY_ROW, EASY_COL);

	//DisplayBoard(show, EASY_ROW, EASY_COL);//打印棋盘
}

void mediumMode()
{
	char mine[MEDIUM_ROWS][MEDIUM_COLS] = { 0 };//初始化为全'0'
	char show[MEDIUM_ROWS][MEDIUM_COLS] = { 0 };//初始化为全'*'
	//初始化棋盘
	InitBoard(mine, MEDIUM_ROWS, MEDIUM_COLS, '0');
	InitBoard(show, MEDIUM_ROWS, MEDIUM_COLS, '*');

	//布置雷
	setMine(mine, MEDIUM_ROW, MEDIUM_COL);

	//DisplayBoard(mine, MEDIUM_ROW, MEDIUM_COL);//打印棋盘

	//排查雷
	CheckMine(mine, show, MEDIUM_ROW, MEDIUM_COL);

	//DisplayBoard(show, MEDIUM_ROW, MEDIUM_COL);//打印棋盘
}

void difficultMode()
{
	char mine[DIFFICULT_ROWS][DIFFICULT_COLS] = { 0 };//初始化为全'0'
	char show[DIFFICULT_ROWS][DIFFICULT_COLS] = { 0 };//初始化为全'*'

	//初始化棋盘
	InitBoard(mine, DIFFICULT_ROWS, DIFFICULT_COLS, '0');
	InitBoard(show, DIFFICULT_ROWS, DIFFICULT_COLS, '*');

	//布置雷
	setMine(mine, DIFFICULT_ROW, DIFFICULT_COL);

	//DisplayBoard(mine, DIFFICULT_ROW, DIFFICULT_COL);//打印棋盘

	//排查雷
	CheckMine(mine, show, DIFFICULT_ROW, DIFFICULT_COL);

	//DisplayBoard(show, DIFFICULT_ROW, DIFFICULT_COL);//打印棋盘
}

void game()
{
	void (*pfArr[])() = { NULL, easyMode, mediumMode, difficultMode };

	if (mode >= 1 && mode < 4)
	{
		pfArr[mode]();
	}
}

void menu()
{
	printf("****************************\n");
	printf("****** 1.play 2.mode *******\n");
	printf("********* 0.exit ***********\n");
	printf("****************************\n");
}

void modeMenu()
{
	printf("****************************\n");
	printf("***** 1.easy  2.medium *****\n");
	printf("****** 3.difficult *********\n");
	printf("****************************\n");
}

void selectMode()
{

	modeMenu();
	while (1)
	{
		printf("选择模式:>");
		scanf("%d", &mode);
		if (mode >= 1 && mode < 4)
		{
			break;
		}
		else
		{
			printf("选择错误，重新选择\n");
		}
	}

}

void test()
{
	int input = 0;
	srand((unsigned int)time(NULL));
	do
	{
		menu();
		printf("请选择:>");
		scanf("%d", &input);

		switch (input)
		{
		case 2:
			system("cls");
			selectMode();
			break;
		case 1:
			system("cls");
			game();
			break;
		case 0:
			system("cls");
			printf("退出游戏\n");
			break;
		default:
			system("cls");
			printf("输入错误，请重新输入\n");
			break;
		}

	} while (input);

}

int main()
{
	test();

	return 0;
}
